import qs from 'qs';

// 获取地址栏参数
export const getUrlParams = () =>{
    let url = window.location.href;
    let query = url.split('?')[1] ? url.split('?')[1].split('#')[0] : '';
    return query? qs.parse(query): {};
}

/**
 * 天龙博弈客户端打开本地的浏览器
 * @param url      跳转地址
 * @param title    标题
 */
export const windowOpen = (url = '',title = '')=>{
	window.prompt(
		"",
		`up://["open_browser",${Date.now()},{"type":"promotion","url":"${url}","title":"${title}"}]`
	);
}

/**
 * 天龙博弈弹出框
 * @param url      链接地址
 * @param title    标题
 * @param type     type 0.新打开标签页 1.新打开子窗口
 */
export function openWeb(url, title, type = 0) {
	window.prompt(
		"",
		`up://["open.web",${Date.now()},{"url":"${url}","title":"${title}","popuptype":${type}}]`
	);
}

/**
 * 打开个股实时行情
 * @param stockCode     股票代码    sz.002041
 * @param type          名称       决策伏击
 * @param block         板块       block
 *
 * @案例
 *
 * 上海：sh
 * 深圳：sz
 *
 * block.880346     板块
 * "sz.002041","sz.002385","sh.600354","sz.000713","sz.000998","sz.300189","sh.600371","sh.600313","sz.300087","sh.601952"
 */
export function stockMarker(stockCode, type, block) {
	
	let pix = stockCode.match(/[a-zA-Z]{2}/g)[0];
	const setcode = pix.toUpperCase == "SZ" ? "0" : "1";
	type = type == undefined ? "" : type;
	let code = '';
	
	if (block) {
		code = stockCode.match(/\d{6}$/)[0];
	} else {
		code = stockCode.match(/\d{6}/)[0];
	}
	window.prompt(
		"",
		`up://["open.stock",${Date.now()},{"setcode":"${
			block ? block : setcode
		}","code":"${code}","type":"${type}"}]`
	);
}
